﻿#include <iostream>
#include <future>
#include <algorithm>
#include "picDeal.h"
#include "everyClass.h"
using namespace std;

int main()
{
	//------------------生成图片的路径，长宽尺寸---------------------------
	char picPath[] = "D://拼接测试//双层.bmp";
	int picH = 1000, picW = 1000;//图片的大小
	long picLenth = picH * picW;
	point pCenter = { 500,500 };//每次刀具改变方向时的旋转中心
	//-------------------画布数组和画布的高度容器------------------------
	byte* pic = new byte[picLenth]{ 0 };
	double Height = 1;//设定的基材最大厚度，是一个相对值无具体单位
	vector<vector<double>> vec(picH, vector<double>(picW, Height));
	//-----------------------------------------------------------------------
	double curW = 50, curDist = 50;//划痕的宽度和走刀的间距
	ToolPath TP(vec, pCenter);
	point pO;
	//=================刻刀==================
	Vec BaseToolDirect = { 0,1 };//刻刀的基准方向向量
	int ProcessNum = 2;//需要几轮转动刀具
	double ProcessAngel = PI / 4;//每轮转动刀具的角度
	for (int n = 0; n < ProcessNum; n++) {
		double RotateAngel = PI / ProcessNum;//单轮里面刀具转动的角度，平分PI
		Vec Process_BaseToolDirect = Rotate_Point(BaseToolDirect, pO, ProcessAngel*n);//计算每轮刀具的走线基准方向
		double ToolDepth = Height;//在这里我将每轮刻刀深度设置成和基材厚度相同
		for (int i = 0; i < 2; i++) {//三棱锥就转动三次，四棱锥就转动两次
			Vec RotateToolDirect = Rotate_Point(Process_BaseToolDirect, pO, PI / 2 * i);
			TP.DriveTool(RotateToolDirect, curW, curDist, ToolDepth);
		}
	}
	//---------------处理完后遍历vec找到最大高度-----------------------
	double max_val = numeric_limits<double>::lowest();
	for (const auto& row : vec) {
		double row_max = *max_element(row.begin(), row.end());
		max_val = max(max_val, row_max);
	}
	//------------------将高度数据转换成灰度数据装入pic数组---------------------
	for (long i = 0; i < picLenth; i++) {
		int iRow = int(i / picW), iCol = i % picW;
		int Gray = 255 * (vec[iRow][iCol] / max_val);
		pic[i] = Gray;
	}
	//--------------------输出图片------------------------
	dealBMP dB(picPath, picW, picH);
	dB.writePic1(pic);
	delete[] pic, pic = nullptr;
	std::cout << "Finish" << endl;
	std::cin.get();
	return 0;
}
